package com.caszx.chargingpile.activity;

import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import com.app.base.adapter.BaseClickRecyclerAdapter;
import com.app.base.adapter.BaseHeadFootAdapter;
import com.app.base.app.BaseTopBarDelayActivity;
import com.caszx.chargingpile.R;
import com.caszx.chargingpile.adapter.GirdDropDownAdapter;
import com.caszx.chargingpile.adapter.ListDropDownAdapter;
import com.caszx.chargingpile.entity.EntityCommPile;
import com.caszx.chargingpile.entity.EntityStation;
import com.caszx.chargingpile.eventbus.EventBusAction;
import com.caszx.chargingpile.holder.reservate.OftenUseHolder;
import com.caszx.chargingpile.holder.station.StationListHolder;
import com.yyydjk.library.DropDownMenu;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import de.greenrobot.event.EventBus;


public class StationListActivity extends BaseTopBarDelayActivity {

    private DropDownMenu mDropDownMenu;
    private String headers[] = {"距离远近", "充电标准", "电桩类型"};
    private String distances[] = {"不限"};
    private String charge[] = {"不限"};
    private String types[] = {"不限"};
    private GirdDropDownAdapter mDistancesAdapter;
    private GirdDropDownAdapter mChargeAdapter;
    private GirdDropDownAdapter mTypeAdapter;
    private List<View> popupViews = new ArrayList<>();

    private RecyclerView mRecyclerView;
    private BaseHeadFootAdapter<EntityStation> mRecyclerAdapter;
    private List<EntityStation> mStations;

    @Override
    protected void init() {
        mStations = getIntent().getParcelableArrayListExtra("STATION");
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_station_list);
        EventBus.getDefault().register(this);
    }


    public void onEvent(String action){
        if(EventBusAction.ACTION_USER_SUCCESS_RESER.equals(action)){
            //预约成功
           finish();
        }
    }
    @Override
    protected void findView() {
        initRecyclerView();
//        mDropDownMenu = (DropDownMenu) findViewById(R.id.dropDownMenu);
//
//        //init distances menu
//        final ListView distancesView = new ListView(this);
//        mDistancesAdapter = new GirdDropDownAdapter(this, Arrays.asList(distances));
//        distancesView.setDividerHeight(0);
//        distancesView.setAdapter(mDistancesAdapter);
//
//        //init charge menu
//        final ListView chargeView = new ListView(this);
//        chargeView.setDividerHeight(0);
//        mChargeAdapter = new GirdDropDownAdapter(this, Arrays.asList(charge));
//        chargeView.setAdapter(mChargeAdapter);
//
//        //init type menu
//        final ListView typeView = new ListView(this);
//        typeView.setDividerHeight(0);
//        mTypeAdapter = new GirdDropDownAdapter(this, Arrays.asList(types));
//        typeView.setAdapter(mTypeAdapter);
//
//        popupViews.add(distancesView);
//        popupViews.add(chargeView);
//        popupViews.add(typeView);
//
//        distancesView.setVisibility(View.GONE);
//        chargeView.setVisibility(View.GONE);
//        typeView.setVisibility(View.GONE);
//
//        //add item click event
//        distancesView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
//            @Override
//            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//                mDistancesAdapter.setCheckItem(position);
//                mDropDownMenu.setTabText(position == 0 ? headers[0] : distances[position]);
//                mDropDownMenu.closeMenu();
//            }
//        });
//
//        chargeView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
//            @Override
//            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//                mChargeAdapter.setCheckItem(position);
//                mDropDownMenu.setTabText(position == 0 ? headers[1] : charge[position]);
//                mDropDownMenu.closeMenu();
//            }
//        });
//
//        typeView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
//            @Override
//            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//                mTypeAdapter.setCheckItem(position);
//                mDropDownMenu.setTabText(position == 0 ? headers[2] : types[position]);
//                mDropDownMenu.closeMenu();
//            }
//        });
//
//        //init context view
//        View contentView = getLayoutInflater().inflate(R.layout.common_recyclerview,null,false);
//        contentView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
//        //init dropdownview
//        mDropDownMenu.setDropDownMenu(Arrays.asList(headers), popupViews, contentView);
//        initRecyclerView(contentView);
    }

    private void initRecyclerView() {
        mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView);
        mRecyclerView.setBackgroundResource(R.color.gray3);
        mRecyclerView.setOverScrollMode(View.OVER_SCROLL_NEVER);
        LinearLayoutManager layoutManager = new LinearLayoutManager( this);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        mRecyclerView.setLayoutManager(layoutManager);
        mRecyclerView.setHasFixedSize(true);

        mRecyclerView.setItemAnimator(new DefaultItemAnimator());
        mRecyclerAdapter = new BaseHeadFootAdapter<>(R.layout.item_station_list,StationListHolder.class);
        mRecyclerView.setAdapter(mRecyclerAdapter);
        mRecyclerAdapter.setDatas(mStations);
    }

    @Override
    public void onBackPressed() {
        //退出activity前关闭菜单
//        if (mDropDownMenu.isShowing()) {
//            mDropDownMenu.closeMenu();
//        } else {
//            super.onBackPressed();
//        }

        super.onBackPressed();
    }


    @Override
    public void finish() {
        super.finish();
        EventBus.getDefault().unregister(this);
        overridePendingTransition(R.anim.activity_right_out,R.anim.activity_push_right_out);
    }
}
